Skip to content

fix(agents): 按完整行双向分页读取会话历史 - #240

Merged
xiaoyumuxi merged 4 commits into
mainfrom
fix/agent-history-pages
Dec 1, 2026
Merged

xiaoyumuxi merged 4 commits into
mainfrom
fix/agent-history-pages

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

关联 Issue

Refs 1lck/Lithe-IDEA#2491

问题与修复

较长会话按固定字节范围读取时可能切断记录行,导致部分问答、思考和工具输出无法查看。宿主也缺少从末尾向前读取、淘汰后反向读回的稳定边界。

  • 新增内部命令 agentSessions.page,按完整行向前或向后分页,校验授权、来源目录、文件快照和 cursor。
  • 初始读取 256 KiB,长行按需增长至 16 MiB;分批调用插件解析器,约束返回消息数量与编码大小,返回 changed / tooLong 状态。
  • 分页读取才传 messageIDs: true,接受并校验可选的稳定消息 id;旧 agentSessions.read 与标题读取维持旧的请求和结果形状。
  • 同步应用契约、插件契约说明、协议更新记录及两份由测试实际消费的 fixture。

API 与兼容性

原计划编号 方法 / 扩展 用途
API-45 内部命令 agentSessions.page 宿主有界双向读取会话,不是新增插件 host method
API-45 会话来源 read 的可选 messageIDs / 消息 id 显式协商稳定身份,允许宿主合并镜像消息

agents 能力、plugin API、schema、SDK 包版本均不变。旧插件可忽略 messageIDs;旧读取不请求 ID。四语 SDK 的会话来源处理器使用已有 JSON 函数,无新增类型接口。没有新增宿主方法、通知或错误码。此 PR 不包含独立的运行中交互工作。

验证

  • cargo test --manifest-path rust/Cargo.toml -p lithe-agent-runtime:32 项通过。
  • agent-runtime / Core clippy、cargo fmt --check、Rust 注释规范:通过。
  • node shared/plugins/scripts/verify-docs.mjs、node scripts/rust-core/verify-platform-tests.mjs:通过。
  • node shared/plugins/scripts/sdk-e2e.mjs:Rust、Go、Node、Java 共 16 项通过。
  • 配套宿主定向测试与 race 检查通过;插件历史解析:Codex 12 项、Claude Code 9 项通过。
  • git diff --check:通过。

Windows 原生验收与真实 CLI 恢复全流程未运行;跨平台 CI 交给仓库工作流,不把本地组件测试作为整机验收。无发布操作。

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 2 potential issues.

3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +696 to +707
if store
.read_range(
&request.agent,
&request.path,
ByteRange {
start: request.size - 1,
end: request.size,
},
)?
.is_none()
{
return Ok(empty(true, false));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Resyncs invalidate history cursors silently

After a file is replaced and synced, page checks old cursors against the latest cached revision. An old end cursor can return replacement messages as valid, or a range error after truncation, instead of changed.

Learn more

The host keeps a listed readBytes value while traversing history. sync_file can rebuild the record for the same path, replacing the revision that read_range checks. The paging request carries no identity for the earlier revision. Once the resync completes, the size probe accepts a same-length replacement or errors if the old size exceeds the new cached offset.

Example: Open a 500 KiB history and retain its readBytes. Replace it with a different 500 KiB history at the same path and sync. A backward request from the old end reads the new tail with changed: false, which the host can combine with retained pages from the old file.

Recommended fix: Return a file generation with the listed record and require it on page requests. Keep that generation stable on verified appends and change it on cache rebuilds for replacements or truncations. Validate the generation before reading and return changed on a mismatch.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

devin-ai-integration[bot]

This comment was marked as resolved.

- 长行不再和前面的短行合成一批:加入后会超过约 64 KiB 的行另起一批,
  避免合并后的回答超过 1 MiB 函数结果上限而让翻页失败
- 旧 agentSessions.read 不请求工具详情,回答里带详情字段(含显式 null)
  时按 agentSessions.invalidRead 拒绝;只有 page 接受
- 会话缓存的文件新增 generation(缓存结构升到 2):文件被替换或截断后
  重新读取时换新值;agentSessions.list 回答它,agentSessions.page 必须
  带上,不一致时回答 changed,同长度替换也能识别
@xiaoyumuxi
xiaoyumuxi merged commit d84f71d into main Dec 1, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant